package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ObjectAttributeMapper;
import com.ruoyi.system.domain.ObjectAttribute;
import com.ruoyi.system.service.IObjectAttributeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 属性Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-04
 */
@Service
public class ObjectAttributeServiceImpl implements IObjectAttributeService 
{
    @Autowired
    private ObjectAttributeMapper objectAttributeMapper;

    /**
     * 查询属性
     * 
     * @param objectId 属性ID
     * @return 属性
     */
    @Override
    public ObjectAttribute selectObjectAttributeById(Long objectId)
    {
        return objectAttributeMapper.selectObjectAttributeById(objectId);
    }

    /**
     * 查询属性列表
     * 
     * @param objectAttribute 属性
     * @return 属性
     */
    @Override
    public List<ObjectAttribute> selectObjectAttributeList(ObjectAttribute objectAttribute)
    {
        return objectAttributeMapper.selectObjectAttributeList(objectAttribute);
    }

    /**
     * 新增属性
     * 
     * @param objectAttribute 属性
     * @return 结果
     */
    @Override
    public int insertObjectAttribute(ObjectAttribute objectAttribute)
    {
        objectAttribute.setCreateTime(DateUtils.getNowDate());
        return objectAttributeMapper.insertObjectAttribute(objectAttribute);
    }

    /**
     * 修改属性
     * 
     * @param objectAttribute 属性
     * @return 结果
     */
    @Override
    public int updateObjectAttribute(ObjectAttribute objectAttribute)
    {
        return objectAttributeMapper.updateObjectAttribute(objectAttribute);
    }

    /**
     * 删除属性对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteObjectAttributeByIds(String ids)
    {
        return objectAttributeMapper.deleteObjectAttributeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除属性信息
     * 
     * @param objectId 属性ID
     * @return 结果
     */
    @Override
    public int deleteObjectAttributeById(Long objectId)
    {
        return objectAttributeMapper.deleteObjectAttributeById(objectId);
    }

    /**
     * 查询属性树列表
     * 
     * @return 所有属性信息
     */
    @Override
    public List<Ztree> selectObjectAttributeTree()
    {
        List<ObjectAttribute> objectAttributeList = objectAttributeMapper.selectObjectAttributeList(new ObjectAttribute());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (ObjectAttribute objectAttribute : objectAttributeList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(objectAttribute.getObjectId());
            ztree.setpId(objectAttribute.getParentId());
            ztree.setName(objectAttribute.getObjectName());
            ztree.setTitle(objectAttribute.getObjectName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
